<template>
  <div class="app-container">
    <!-- 放置表单 -->
    <el-form ref="userForm" label-width="60px" :rules="rules" :model="userInfo">
      <el-form-item prop="username" label="姓名:">
        <el-input v-model="userInfo.username" style="width: 300px" />
      </el-form-item>
      <el-form-item prop="mobile" label="手机号:">
        <el-input v-model="userInfo.mobile" disabled style="width: 300px" />
      </el-form-item>
      <el-form-item prop="password" label="密码:">
        <el-input v-model="userInfo.password" disabled type="password" style="width: 300px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="updateInfo">更新</el-button>
        <el-button>返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { saveUserDetailById } from '@/api/employee.js'
export default {
  props: {
    userInfo: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      rules: {
        username: [{ required: true, min: 3, max: 6, message: '用户名必填！', trigger: 'change' }]
      }
    }
  },
  methods: {
    updateInfo() {
      this.$refs.userForm.validate(async(isok) => {
        if (isok) {
          await saveUserDetailById(this.userInfo)
          this.$message.success('操作成功！')
          this.$router.back()
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
